#include <map>
#include <functional>

class CDoCmd
{
    std::map<String, std::function<void()>> m_cmdfun;
    CDoCmd() {}

public:
    static CDoCmd &getSingleton()
    {
        static CDoCmd _singleton;
        return _singleton;
    }

    void pushCmd(const char *cmdstr, std::function<void()> &&fun)
    {
        if ((cmdstr != nullptr) && fun)
            m_cmdfun[cmdstr] = std::move(fun);
    }

    bool doCmd(const String &cmdstr)
    {
        auto ite = m_cmdfun.find(cmdstr);
        if (ite != m_cmdfun.end())
        {
            ite->second();
            return true;
        }
        return false;
    }
};